1
/******************************** Module Header ********************************\
2 * Module Name: WTSHelper.cs
3 * Project: CSInteractiveWindowsService
4 * Copyright (c) Microsoft Corporation.
6 * To be finished - Jialiang Ge
7 * Ref: http://files.codes-sources.com/fichier.aspx?id=47023&f=WTSLib/WTSLib/WTSHelper.cs
9 * This source is subject to the Microsoft Public License.
10 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 * All other rights reserved.
13 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 \*******************************************************************************/
20 using System
.Runtime
.InteropServices
;
23 namespace CSInteractiveWindowsService
28 /// Retrieves the Remote Desktop Services session that is currently
29 /// attached to the physical console. The physical console is the monitor,
30 /// keyboard, and mouse. If there is no session attached to the physical
31 /// console, (for example, if the physical console session is in the
32 /// process of being attached or detached), this function returns
35 public static uint ActiveConsoleSessionId
37 get { return WTSGetActiveConsoleSessionId(); }
40 [DllImport("kernel32.dll", CharSet
= CharSet
.Auto
, SetLastError
= true)]
41 private static extern uint WTSGetActiveConsoleSessionId();
43 [DllImport("wtsapi32.dll", CharSet
= CharSet
.Auto
, SetLastError
= true)]
44 [return: MarshalAs(UnmanagedType
.Bool
)]
45 private static extern bool WTSEnumerateSessions(IntPtr hServer
,
46 uint reserved
, uint version
, out IntPtr ppSessionInfo
, out uint count
);
48 [DllImport("wtsapi32.dll", CharSet
= CharSet
.Auto
, SetLastError
= true)]
49 private static extern bool WTSQuerySessionInformation(IntPtr hServer
,
50 uint sessionId
, WTS_INFO_CLASS wtsInfoClass
, out IntPtr ppBuffer
,
51 out uint bytesReturned
);
53 [DllImport("wtsapi32.dll", CharSet
= CharSet
.Auto
, SetLastError
= false)]
54 private static extern void WTSFreeMemory(IntPtr memory
);
57 public static readonly IntPtr WTS_CURRENT_SERVER_HANDLE
= IntPtr
.Zero
;
62 /// The WTS_SESSION_INFO structure contains information about a client
63 /// session on a Remote Desktop Session Host (RD Session Host) server.
65 [StructLayout(LayoutKind
.Sequential
)]
66 struct WTS_SESSION_INFO
68 public uint SessionID
;
70 [MarshalAs(UnmanagedType
.LPTStr
)]
71 public string WinStationName
;
73 public WTS_CONNECTSTATE_CLASS State
;
78 /// Specifies the connection state of a Remote Desktop Services session.
80 enum WTS_CONNECTSTATE_CLASS
96 /// The WTS_INFO_CLASS enumeration type contains values that indicate the
97 /// type of session information to retrieve in a call to the
98 /// WTSQuerySessionInformation function.
111 WTSClientBuildNumber
,
118 WTSClientProtocolType
,